package com.google.code.UtopiaXml;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Abstract class representing an xs:element.
 *
 * @author Michael Simacek
 */
public abstract class Element implements IndicatorContent {

    private String elementName;
    private Property prop;

    /**
     * Creates element with given name and property.
     *
     * @param elementName
     * @param property
     */
    protected Element(String elementName, Property property) {
        if (property == null) {
            throw new IllegalArgumentException("property");
        }
        this.prop = property;
        this.elementName = elementName;
    }

    /**
     * Returns original (unconverted) name of element that was used in XSD
     *
     * @return original name
     */
    public String getElementName() {
        return elementName;
    }

    @Override
    public List<String> getMatchStrings() {
        List<String> list = new ArrayList<>();
        list.add(getElementName());
        return list;
    }

    /**
     * Returns converted name of the Element.
     *
     * @return name of the property
     */
    public String getName() {
        return prop.getName();
    }

    /**
     * Returns element type.
     *
     * @return element type
     */
    public Type getType() {
        return prop.getType();
    }

    @Override
    public Set<Property> getProperties() {
        Set<Property> props = new HashSet<>();
        props.add(prop);
        return props;
    }
}
